package divisibilityby8;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Solution {
	Set<Integer> multiplesOfEightAll = null;
        public Solution() {
        	multiplesOfEightAll = new HashSet<Integer>();
            for(int i = 104; i < 1000; i+=8){
            	multiplesOfEightAll.add(i);
        	}
        }

        public static void main(String[] args) {
               
                Scanner sc = new Scanner(System.in);
                String line = sc.nextLine();
                int n = Integer.parseInt(line);
                while (n > 0){
                        n--;
                        String value = sc.nextLine();
                        Solution sol = new Solution();
                       
                        char[] digits = value.trim().toCharArray();
                        boolean divisible=false;
                       
                        if(digits.length >=3){
                                divisible = sol.isDivisibleByEightForDigit3(value);
                        }
                        if(digits.length ==2){
                                divisible = sol.isDivisibleBy8ForDigit2(digits);
                        }
                        if(digits.length ==1){
                                if((Integer.parseInt(value.trim())%8 == 0)){
                                        divisible = true;                              
                                }
                        }
                        if(divisible){
                                System.out.println("YES");
                        }else{
                                System.out.println("NO");
                        }
                }
                sc.close();
        }
        public boolean isDivisibleByEightForDigit3(String inputNumber){
        	boolean isDivisible = false;
        	List<Integer> digitList = new ArrayList<Integer>(); 
        	for(Integer i : multiplesOfEightAll){
        		String value = i.toString();
        		char[] digits = value.toCharArray();
        		
        		for(char c : digits){
        			int index = inputNumber.indexOf(c);
        			while(index >=0){
    	    			if(!digitList.contains(index)){
    	    				digitList.add(index);
    	    				break;
    	    			}  
    	    			index = inputNumber.indexOf(c, index+1);
        			}
        		}
        		if(digitList.size() == 3){
        			isDivisible = true;
        			break;
        		}
        		digitList.clear();
        	}
        	return isDivisible;
        }       
        public boolean isDivisibleBy8ForDigit3(char[] digits){
               
                String value = "";
                boolean isDivisible = false;
                for(int i = 0; i < digits.length;i ++){
                        for(int j = 0;j< digits.length; j++){
                                if(j == i ){
                                        continue;
                                }
                                for(int k = 0; k < digits.length; k++){
                                        if(k == i || k == j){
                                                continue;
                                        }
                                        value = digits[i] +""+ digits[j] + ""+digits[k];
                                        int intValue = Integer.parseInt(value);        
                                        System.out.println(intValue);
                                        if((intValue%8) == 0){
                                                isDivisible = true;
                                                break;
                                        }
                                }
                                if(isDivisible)break;
                        }
                        if(isDivisible)break;
                }
                return isDivisible;
        }
        public boolean isDivisibleBy8ForDigit2(char[] digits){
               
                String value = "";
                boolean isDivisible = false;
                for(int i = 0; i < digits.length;i ++){
                        for(int j = 0;j< digits.length; j++){
                                if(j == i ){
                                        continue;
                                }
                                value = digits[i] +""+ digits[j];
                                int intValue = Integer.parseInt(value);
                                if((intValue%8) == 0){
                                        isDivisible = true;
                                        break;
                                }
                               
                        }
                        if(isDivisible)break;
                }
                return isDivisible;
        }
}